home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: open vs fopen?
- Date: Fri, 09 Feb 96 23:06:23 GMT
- Organization: none
- Message-ID: <823907183snz@genesis.demon.co.uk>
- References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f7v8u$3s2@unix.sri.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4f7v8u$3s2@unix.sri.com> mklenk@coronacorp.com "Mark Klenk" writes:
-
- >Nathan Wild asked:
- >>
- >>In C, why would one use open and DOS int handles rather than fopen and
- >>stdio file handles?
- >
- > open() and family are really UNIX-isms that DOS adopted.
- >
- > To answer your question, though:
- >
- > a) file I/O through open/close/read/write/lseek is generally
- > unbuffered and therefore in some cases faster, especially
- > in random-access situations
-
- That is debatable. Where open etc. can be a win is if you create your own
- buffering which is optimised to the code's usage patterns. FILE buffering
- isn't bad but it is generalised and may not be optimal for specific
- cases.
-
- In Unix open() gives you finer control over the file mode and options
- not available on fopen. 'int handles' are also used for other system
- provided functions such as record locking and dealing with special/device
- files. They are probably not as useful in DOS.
-
- > b) ANSI C only defines fopen/fclose/fread/fwrite/fseek, which
- > by default usually provide buffered, but more portable, I/O
-
- Right so if these do the job they are generally the appropriate choice.
- They are also generally easier to use since you don't have to worry about
- buffering yourself and you get powerful functions like printf. The
- bottom line is that since open() isn't part of the C language you can't
- use it in 'portable' C code.
-
- > c) for sequential access, the f*() functions can improve I/O
- > performance because they generally do read-ahead and
- > write-behind in order to match system block-sizes more
- > closely
-
- No, they don't (at least not any of the ones I've come across). To do this
- would require asynchronous file I/O. It is almost always the OS that performs
- any read-ahead hence both fopen and open style reads get the benefit.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-